<template>
  <div class="favorite-playlists">
    <h2>我的收藏</h2>
    <div v-if="loading" class="loading">加载中...</div>
    <div v-else-if="!userStore.userId" class="empty-tip">
      请先登录后查看收藏的歌单
    </div>
    <div v-else-if="error" class="error">{{ error }}</div>
    <div v-else-if="!favoritePlaylists.length" class="empty-tip">
      还没有收藏任何歌单，去发现好音乐吧~
    </div>
    <div v-else class="playlists-grid">
      <div 
        v-for="playlist in favoritePlaylists" 
        :key="playlist.id" 
        class="playlist-card"
        @click="goToPlaylist(playlist.id)"
      >
        <div class="card-stack">
          <div class="card-layer"></div>
          <div class="card-layer"></div>
          <div class="main-card">
            <img :src="playlist.cover" :alt="playlist.name">
            <div class="playlist-info">
              <h3>{{ playlist.name }}</h3>
              <p>{{ playlist.description }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { getFavoritePlaylists } from '@/api/playList';
import { useUserStore } from '@/stores/user';
import type { PlayList } from '@/api/playList';

const router = useRouter();
const userStore = useUserStore();
const favoritePlaylists = ref<PlayList[]>([]);
const loading = ref(true);
const error = ref('');

const fetchFavoritePlaylists = async () => {
  if (!userStore.userId) {
    error.value = '请先登录';
    loading.value = false;
    return;
  }

  try {
    const response = await getFavoritePlaylists();
    if (response.success && response.favoritePlaylists) {
      favoritePlaylists.value = response.favoritePlaylists;
    } else {
      error.value = response.message;
    }
  } catch (err) {
    error.value = '获取收藏歌单失败';
  } finally {
    loading.value = false;
  }
};

const goToPlaylist = (id: string) => {
  router.push(`/playlist/${id}`);
};

onMounted(fetchFavoritePlaylists);
</script>

<style lang="scss" scoped>
@import '@/styles/variables.scss';

.favorite-playlists {
  padding: 24px;
  border-radius: 16px;
  margin-bottom: 30px;
}

/* 删除或注释掉以下样式 */
/*h2 {
  color: var(--primary-color);
  font-size: 1.8em;
  margin-bottom: 28px;
  font-weight: 600;
  letter-spacing: 0.5px;
  background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  position: relative;
  display: inline-block;
}

h2::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 0;
  width: 60px;
  height: 3px;
  background: linear-gradient(to right, var(--secondary-color), transparent);
  border-radius: 2px;
}*/

.playlists-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 40px;
  padding: 20px 0;
}

.playlist-card {
  position: relative;
  padding-top: 20px;
  padding-right: 20px;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  height: 300px;
}

.card-stack {
  position: relative;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  height: 100%;
}

.card-layer {
  position: absolute;
  background: color-mix(in srgb, var(--bgc-color-2) 40%, transparent);
  border-radius: 12px;
  inset: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(4px);
  border: 1px solid color-mix(in srgb, var(--primary-color) 3%, transparent);
}

.card-layer:nth-child(1) {
  top: -8px;
  right: -8px;
  background: color-mix(in srgb, var(--bgc-color-2) 30%, transparent);
}

.card-layer:nth-child(2) {
  top: -4px;
  right: -4px;
  background: color-mix(in srgb, var(--bgc-color-2) 45%, transparent);
}

.main-card {
  position: relative;
  background: color-mix(in srgb, var(--bgc-color-2) 60%, transparent);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--primary-color) 5%, transparent);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 20px var(--theme-shadow);
  height: 100%;
  display: flex;
  flex-direction: column;
}

.main-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--bgc-color-2) 70%, transparent),
    transparent
  );
  opacity: 0;
  transition: opacity 0.4s ease;
}

.main-card img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.playlist-info {
  padding: 15px;
  background: color-mix(in srgb, var(--bgc-color-2) 60%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid color-mix(in srgb, var(--primary-color) 5%, transparent);
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 85px;
  min-height: 0;
  justify-content: flex-start;
}

.playlist-info h3 {
  color: var(--primary-color);
  font-size: 1.1em;
  margin-bottom: 8px;
  font-weight: 500;
  letter-spacing: 0.3px;
  transition: all 0.3s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-info p {
  color: rgba(var(--primary-color), 0.7);
  font-size: 0.9em;
  line-height: 1.5;
  transition: all 0.3s ease;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
}

/* 悬浮效果 */
.playlist-card:hover {
  transform: translateY(-4px);
}

.playlist-card:hover .card-layer:nth-child(1) {
  transform: translate(12px, 12px);
  background: color-mix(in srgb, var(--bgc-color-2) 35%, transparent);
}

.playlist-card:hover .card-layer:nth-child(2) {
  transform: translate(6px, 6px);
  background: color-mix(in srgb, var(--bgc-color-2) 50%, transparent);
}

.playlist-card:hover .main-card {
  box-shadow: 
    0 10px 20px color-mix(in srgb, var(--bgc-color-1) 20%, transparent),
    0 4px 24px color-mix(in srgb, var(--secondary-color) 15%, transparent);
  border-color: color-mix(in srgb, var(--primary-color) 10%, transparent);
}

.playlist-card:hover .main-card::after {
  opacity: 1;
}

.playlist-card:hover .main-card img {
  transform: scale(1.05);
}

.playlist-card:hover .playlist-info h3 {
  color: var(--secondary-color);
  transform: translateY(-1px);
}

.playlist-card:hover .playlist-info p {
  color: rgba(var(--primary-color), 0.85);
}

.empty-tip {
  text-align: center;
  padding: 48px 0;
  color: rgba(var(--primary-color), 0.7);
  font-size: 15px;
}
</style> 